package com.itheima.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.io.PrintWriter;

@WebFilter("/*")
public class FilterDemo1 implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = response.getWriter();
        writer.print("我是过滤器");
        String username = request.getParameter("username");
        if ("zhangsan".equals(username)){

            filterChain.doFilter(request,response);
        }else {
            PrintWriter writer1 = response.getWriter();
            writer1.print("你不能执行ServletDemo1");
        }
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void destroy() {

    }
}
